package com.boarsoft.boar.demo.product;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.boarsoft.boar.demo.product.entity.PocProduct;
import com.boarsoft.boar.demo.product.service.PocProductService;
import com.boarsoft.common.Util;

public class ProductAppTestMain {
	private static final Logger log = LoggerFactory.getLogger(ProductAppTestMain.class);
	private static ClassPathXmlApplicationContext ctx;

	public static void main(String[] args) {
		ctx = new ClassPathXmlApplicationContext("classpath:conf/context.xml");
		System.out.println("Startup ".concat(ctx.isRunning() ? "successfully." : "failed."));

		testAdd(ctx);
		// testFind(ctx);
	}

	public static void testAdd(ClassPathXmlApplicationContext ctx) {
		PocProductService pocProductService = ctx.getBean(PocProductService.class);
		PocProduct p = new PocProduct();
		p.setProductId(4);
		p.setProductName("钉子");
		p.setProductPrice(1);
		p.setStoreNum(Integer.MAX_VALUE);
		p.setCreateTime(Util.getStdmfDateTime());
		p.setModifyTime(Util.getStdmfDateTime());
		pocProductService.add(p);
		log.info("Product added");
	}

	public static void testFind(ClassPathXmlApplicationContext ctx) {
		PocProductService pocProductService = ctx.getBean(PocProductService.class);
		PocProduct m = pocProductService.get(3);
		System.out.println(m.getProductName());
	}

}
